package com.meixiang.adapter.myFundAdapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.meixiang.R;
import com.meixiang.entity.fund.FundIndexResult;
import com.meixiang.entity.fund.FundInfoBean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 我的基金 --精品推荐
 * author:xyj
 */
public class FundListRecommendAdapter extends com.meixiang.recyclerview.RecyclerAdapter<FundListRecommendAdapter.ViewHolder> {
    private Context mContext;
    private List<FundIndexResult.FundSiftBean> mFundSiftBean;

    public FundListRecommendAdapter(Context context) {
        this.mContext = context;
    }

    /**
     * 刷新数据
     */
    public void refreshData(List<FundIndexResult.FundSiftBean> list) {
        mFundSiftBean = list;
        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.list_fund_recommend_fragment_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        holder.tv_fund_class.setText(mFundSiftBean.get(position).getSift_title());
        holder.tv_fund_detail.setText(mFundSiftBean.get(position).getSift_desc());
        holder.tv_fund_name.setText(mFundSiftBean.get(position).getFund_name());
        holder.tv_fund_buy_rate.setText(mFundSiftBean.get(position).getRate());
        holder.tv_fund_buy_number.setText(mFundSiftBean.get(position).getCnt());
        holder.tv_fund_earnings_hint.setText(mFundSiftBean.get(position).getRate_desc());
    }

    @Override
    public int getItemCount() {
        return mFundSiftBean == null ? 0 : mFundSiftBean.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_fund_class)
        TextView tv_fund_class;
        @Bind(R.id.tv_fund_detail)
        TextView tv_fund_detail;
        @Bind(R.id.tv_fund_name)
        TextView tv_fund_name;
        @Bind(R.id.tv_fund_buy_rate)
        TextView tv_fund_buy_rate;
        @Bind(R.id.tv_fund_buy_number)
        TextView tv_fund_buy_number;
        @Bind(R.id.tv_fund_earnings_hint)
        TextView tv_fund_earnings_hint;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

}
